import React, { useEffect } from 'react';
import Router from './router';
import { useNavigate } from 'react-router-dom';


const App = () => {
  return (
    <Router></Router>  
  )
}



// 高阶组件：是个函数，函数接受组件参数，返回值是一个组件
const withLogin = (Comp) => {
  return () => {
    const token = localStorage.getItem('token')
    const navigate = useNavigate()
    // 拦截逻辑
    useEffect(() => {
      if(!token) {
        navigate('/login')
      }
    }, [token])
    return <Comp></Comp>
  }
}

export default withLogin(App)

